package com.codegenerate.demo.dto;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.codegenerate.demo.config.R;
import com.codegenerate.demo.entity.GTable;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.time.LocalDateTime;

public class GTableDto implements Serializable {
    private long id;

    int pageNum;
    int pageSize;
    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public R validateUpdate(){
        if(this.getId()<0){
            return R.failed("id 不能为空");
        }
        return R.ok(null);
    }










    /**
     *
     */
    private String tableName;




    /**
     *
     */
    private String tableNameChinese;




    /**
     *
     */
    private int delState;









    public long getId() {
        return id;
    }
    public void setId(long id) {
        this.id = id;
    }

    public String getTableName() {
        return tableName;
    }
    public void setTableName(String tableName) {
        this.tableName = tableName;
    }

    public String getTableNameChinese() {
        return tableNameChinese;
    }
    public void setTableNameChinese(String tableNameChinese) {
        this.tableNameChinese = tableNameChinese;
    }

    public int getDelState() {
        return delState;
    }
    public void setDelState(int delState) {
        this.delState = delState;
    }




    /**
     * build
     */
    public static GTableDto build(){
        GTableDto temp = new GTableDto();



        temp.setId(0);

        temp.setTableName("");

        temp.setTableNameChinese("");

        temp.setDelState(1);


        return temp;
    }

    /**
     * setDefaultValue
     */
    public void  setDefaultValue(GTableDto temp){

        if(this.id<=0){
            temp.setId(0);
        }

        if(StringUtils.isEmpty(this.tableName)){
            temp.setTableName("");
        }

        if(StringUtils.isEmpty(this.tableNameChinese)){
            temp.setTableNameChinese("");
        }

        if(this.delState<=0){
            temp.setDelState(1);
        }

    }



    /**
     * dto2entity
     */
    public GTable dto2entity(){
        var entity=GTable.build();

        if(this.id>0){
            entity.setId(this.getId());
        }

        if(!StringUtils.isEmpty(this.tableName)){
            entity.setTableName(this.getTableName());
        }

        if(!StringUtils.isEmpty(this.tableNameChinese)){
            entity.setTableNameChinese(this.getTableNameChinese());
        }

        if(this.delState>0){
            entity.setDelState(this.getDelState());
        }

        return entity;
    }



    public Page<GTable> buildPage(){
        Page<GTable> tempage = new Page<GTable>();
        tempage.setCurrent(this.getPageNum()<=0?0:this.getPageNum());
        tempage.setSize(this.getPageSize()<=0?10:this.getPageSize());
        return tempage;
    }


}